package com.glsc.ngateway.platform.controller;

import com.glsc.ngateway.common.api.oaflow.resp.OaflowResponse;
import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.platform.service.itflow.schedule.PlatformSyncOaflowTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: xc
 * @Date: 2021/10/20
 * @Desc: 作业信息管理
 */
@RestController
@RequestMapping("/dolphinScheduler")
@Api(value = "DolphinSchedulerController", tags = {"作业信息管理管理接口"})
public class DolphinSchedulerController {

    private static Logger logger = LoggerFactory.getLogger(DolphinSchedulerController.class);

    @Autowired
    private PlatformSyncOaflowTask platformSyncOaflowTask;

    @GetMapping("/syncTodoFlow")
    @ApiOperation(value = "syncTodoFlow", notes = "执行")
    public PlatformResponse<?> syncTodoFlow() {
        try{
            logger.info("开始执行任务：syncTodoFlow");
            OaflowResponse<Void> oaflowResponse = platformSyncOaflowTask.syncTodoFlow();
            if(!oaflowResponse.isSuccess()){
                return PlatformResponse.failedMsg("操作失败", oaflowResponse.getMsg());
            }
        } catch (Exception e){
            logger.error("异常", e);
            return PlatformResponse.failedMsg("操作失败", e.getMessage());
        }

        return PlatformResponse.successMsg("成功");
    }
}
